//引入模型
require('../model/exerciseModel');
require('../model/testsModel');
const mongoose = require('mongoose');



//获取所有的考过的试卷
async function getNowTest(req,res,next) {
    let {exerciseId}=req.body;
 
    //通过考试id获取当前试卷"610bce08a50c00009700644e"
    let test=await mongoose.model('testsModel').find({_id:exerciseId}).populate("typeId");
    //获取当前试卷的习题id
    let array=test[0].exercisesId;
    let exercises=[];
    //遍历习题id，如果匹配就从习题库放到数组中，
    for(i=0;i<array.length;i++){
        let id=array[i];
        let exercise =await mongoose.model('exercisesModel').find({_id:id}).populate("pointId");
        console.log(exercise);
        exercises.push(exercise);
    }
    // let exe=array.forEach(a => async function() {
    //     console.log(a);
    //     let id=a;
    //     let exercise =await mongoose.model('exercisesModel').find({_id:id}).populate("pointId");
    //     console.log(exercise);
    // });
 
    
    //let array=test.exercisesId;
  console.log(exercises);
    res.send({exercises, test});
}

//getAllExercises();
module.exports = {
   getNowTest
}